package dao;


import java.util.HashMap;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.TypedQuery;

import basicas.Usuario;



public class DAOUsuario extends DAOGenerico<Usuario> implements IDAOUsuario{

    protected EntityManager entityManager; 
  
    @SuppressWarnings("unchecked") 
    public DAOUsuario(){ 
    	HashMap<String, String> properties = new HashMap<String, String>();
    	properties.put("ConnectionDriverName", "com.mysql.jdbc.Driver"); 
    	EntityManagerFactory emf = Persistence.createEntityManagerFactory("psc_projeto", properties); 
    	entityManager = emf.createEntityManager(); 
   
    } 
    
    @Override
	public Usuario consultarPorEmail(String email) { 
    	
        try { 
            String sql = "Select u from Usuario u WHERE u.email = :n"; 
            TypedQuery<Usuario> query = entityManager.createQuery(sql, Usuario.class); 
            query.setParameter("n", email);
            return query.getSingleResult(); 
        } catch (Exception e) { 
            e.printStackTrace(); 
        } 
        return null; 
    }
    
	
}
